package edu.cuit.copilot.listener;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisMessageListener implements MessageListener {
    @Resource(name = "redisTemplate") private RedisTemplate template;
    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("消息订阅渠道channel:" + new String(pattern));
        //获取消息
        var body = message.getBody();
        //使用redis的value的序列化去抓换消息
        Object message2 = template.getValueSerializer().deserialize(body);
        //System.out.println(message.getChannel());
    }
}
